<template>
  <div>
    <!-- <div id="top">
      <div class="bac">
         <div class="black"></div> 

        <nav>
          <img src="../assets/img/others/logo.png" alt="no found" />
          <dv class="user">
            <img src="../assets/img/others/tx.jpg" />
          </dv>
        </nav>
      </div>

      <div class="search">
        <div class="search-font">搜索图书</div>
        <div class="search-box">
          <input type="text" id="search" v-model="bookName" />
          <button id="searchBtn" @click.enter="search"></button>
        </div>
      </div>
    </div> -->
    <div class="top">
      <div class="black"></div>
      <div class="y">
        <nav>
          <img src="../assets/img/others/logo.png" alt="no found" />
          <div class="user">
            <div class="userbox">
              
              <img src="../assets/img/others/tx.jpg" />
              <div class="menu">
                <ul>
                   <li><img class="tui" src="../assets/img/others/zhang.png" style="vertical-align:middle;"><span style="vertical-align:middle;">账号安全</span></li>
                   <li><img class="tui" src="../assets/img/others/ge.png" style="vertical-align:middle;"><span style="vertical-align:middle;">个人中心</span></li>
                  <div class="lli"></div>
                  <li @click="out"><img class="tui" src="../assets/img/others/tui.png" style="vertical-align:middle;"><span style="vertical-align:middle;">退出登录</span></li>
                </ul>
              </div>
            </div>
          </div>
        </nav>
        <div class="search">
          <div class="search-font">搜索图书</div>
          <div class="search-box">
            <input type="text" id="search" v-model="bookName" />
            <button id="searchBtn" @click.enter="search"></button>
          </div>
        </div>
      </div>
    </div>
    <div class="select" v-if="identity">
      <router-link tag="div" :to="{ name: 'homePage' }">首页</router-link>
      <router-link tag="div" :to="{ name: 'task' }">发布任务</router-link>
      <router-link tag="div" :to="{ name: 'recommend' }">书香门第</router-link>
      <router-link tag="div" :to="{ name: 'community' }">作品社区</router-link>
      <div>海洋世界</div>
      <router-link tag="div" :to="{ name: 'course' }">名师微课</router-link>
      <router-link tag="div" :to="{ name: 'answer' }">故事新编</router-link>
      <router-link tag="div" :to="{ name: 'teacherRead' }"
        >教师阅读</router-link
      >
    </div>
    <div class="select" v-else>
      <router-link tag="div" :to="{ name: 'homePage' }">首页</router-link>
      <router-link tag="div" :to="{ name: 'mytask' }">我的任务</router-link>
      <router-link tag="div" :to="{ name: 'recommend' }">书香门第</router-link>
      <router-link tag="div" :to="{ name: 'community' }">作品社区</router-link>
      <div>海洋世界</div>
      <router-link tag="div" :to="{ name: 'course' }">名师微课</router-link>
      <router-link tag="div" :to="{ name: 'answer' }">故事新编</router-link>
      <router-link tag="div" :to="{ name: 'teacherRead' }"
        >家长阅读</router-link
      >
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      bookName: "",
      bookid: "",
      path: "answer",
      booksinfo: [],
     identity:true,
    };
  },
  mounted(){
    console.log(this.$route.query.identity);
    if(this.$route.query.identity=='student'){
      this.identity=false
    }
  },
  methods: {
    out(){
      this.$router.push({
        name: "login",
        query: { t: Date.now() },

      });
      setTimeout(function () {
         window.location.reload();
        }, 0.1);
    },
    
    routerChange(url) {
      this.$router.push({ name: url });
    },
    search() {
      console.log("search");
      axios
        .post("http://localhost:3000/api/user/booksearch", {
          bookname: this.bookName,
        })
        .then((response) => {
          console.log(response);
          if (response.data.length > 0) {
            this.booksinfo = response.data;
          }
          // this.bookid = response.data[0].bookid;
          this.$router.push({
            name: "booksearchinfo",
            query: { booksinfo: this.booksinfo, t: Date.now() },
          });
        });
      this.bookName = "";
    },
  },
  computed: {},
};
</script>

<style  scoped>
@import "../assets/css/Index";
.router-link-active {
  color: #0064f9;
}
</style>